﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FullThrustLogic.Core;
using FullThrustLogic.Core.GameState;
using FullThrustLogic.ShipComponent;
using LogicTest.Controls;

namespace LogicTest
{
    public partial class GameStateTest : Form
    {
        private GameContext _gameContext;
        private MapControl _mapControl;

        public GameStateTest()
        {
            InitializeComponent();
        }

        private void GameStateTest_Load(object sender, EventArgs e)
        {
            _gameContext = new GameContext();

            _mapControl = new MapControl(_gameContext) { Dock = DockStyle.Fill };
            splitContainer1.Panel2.Controls.Clear();
            splitContainer1.Panel2.Controls.Add(_mapControl);

            _gameContext.OnGameStateChanged -= new GameContext.GameStateChangedHandler(_gameContext_OnGameStateChanged);
            _gameContext.OnGameStateChanged += new GameContext.GameStateChangedHandler(_gameContext_OnGameStateChanged);

            if(_gameContext.CurrentState is CreateGameState)
            {
                ((CreateGameState)_gameContext.CurrentState).CreateNewGame();
                UpdateMap();
                _mapControl.AssignReporting();
            }
        }

       

        void _gameContext_OnGameStateChanged(object sender, EventArgs e)
        {

            if (_gameContext.CurrentState is MovementState)
            {
                splitContainer1.Panel1.Controls.Clear();
                splitContainer1.Panel1.Controls.Add(new AssignMovement(_gameContext, _mapControl) { Dock = DockStyle.Fill });
                UpdateMap();
            }
            else if (_gameContext.CurrentState is AttackOrderState)
            {
                splitContainer1.Panel1.Controls.Clear();
                splitContainer1.Panel1.Controls.Add(new AssignAttack(_gameContext, _mapControl) { Dock = DockStyle.Fill });
                UpdateMap();
            }
        }

        private void UpdateMap()
        {
            if(_mapControl!= null)
            {_mapControl.UpdateMap(null);}
        }
    }
}
